(function($){
    function get_cookie(sMainName, sSubName)
    {
        var re = new RegExp((sSubName ? sMainName + "=(?:.*?&)*?" + sSubName + "=([^&;$]*)" : sMainName + "=([^;$]*)"),"i");
        return re.test(unescape(document.cookie)) ? RegExp["$1"] : "";
    }
    //备份jquery的ajax方法  
    var _ajax=$.ajax;
    //重写jquery的ajax方法
    $.ajax=function(opt){
        //备份opt中success方法
        /*var fn = {
            success:function(data, textStatus){},
            beforeSend:function(XMLHttpRequest){}
        }
        if(opt.success){
            fn.success=opt.success;
        }
        if(opt.beforeSend){
            fn.beforeSend=opt.beforeSend;
        }*/
        var old = $.extend(true,{},opt);
        //扩展增强处理
        var _opt = $.extend(opt,{
            success:function(data, textStatus){
                //成功回调方法增强处理
                try{
                    if(data.error_code==1011){
                        window.location.href = "/login";
                        return false;
                    }
                } catch(e){

                }
                if($.isFunction(old.success))
                {
                    old.success.apply(this,arguments);
                }
            },
            beforeSend:function(xhr)
            {
                //console.log(opt.url);
                //return false;
                xhr.setRequestHeader("x-csrf-token",get_cookie("__CSRF__"));
                if($.isFunction(old.beforeSend))
                {
                    old.beforeSend.apply(this,arguments);
                }
            }
        });
        return _ajax(_opt);
    };
})(jQuery);